import tkinter as tk
window=tk.Tk()
from tkinter import filedialog
from .add_task import add_task_func

def create_card_dialog_func():
    dialog = tk.Toplevel(window)
    dialog.title("Create New Task")
    dialog.geometry("400x300")

    # 创建输入框
    task_name_var = tk.StringVar()
    priority_var = tk.StringVar()
    due_data_var = tk.StringVar()
    image_path_var = tk.StringVar()

    task_name_label = tk.Label(dialog, text="Task Name:")
    task_name_label.pack(pady=5)
    task_name_entry = tk.Entry(dialog, textvariable=task_name_var)
    task_name_entry.pack(pady=5)

    priority_label = tk.Label(dialog, text="Priority:")
    priority_label.pack(pady=5)
    priority_entry = tk.Entry(dialog, textvariable=priority_var)
    priority_entry.pack(pady=5)

    due_data_label = tk.Label(dialog, text="Due Date:")
    due_data_label.pack(pady=5)
    due_data_entry = tk.Entry(dialog, textvariable=due_data_var)
    due_data_entry.pack(pady=5)

    # 创建选择图片功能
    def select_image():
        filename = filedialog.askopenfilename(title="Select Image", filetypes=[("Image Files", "*.png;*.jpg;*.jpeg;*.gif")])
        if filename:
            image_path_var.set(filename)

    # 创建确认按钮
    confirm_button = tk.Button(dialog, text="Confirm", command=lambda: add_task_func(task_name_var.get(), priority_var.get(), due_data_var.get(), image_path_var.get(), dialog))
    confirm_button.pack(pady=10)

    # 创建选择图片按钮
    select_image_button = tk.Button(dialog, text="Select Image", command=select_image)
    select_image_button.pack(pady=5)

    return dialog
